﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="filter_Class_Fee.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Accountant.filter_Class_Fee" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <%
        if (this.cls != 0)
        {
            var get_class = new TblClassController().FetchAll().Where(x => x.Id == this.cls).Single();
            var get_user = new TblUserController().FetchAll().Where(x => x.ClassX == get_class.Id);
            foreach (TblUser user in get_user)
            {
                var get_user_bill = new TblStudyFeeController().FetchAll().Where(x => x.UserId == user.UserId).ToList();
                if (get_user_bill.Count != 0)
                {
                    var get_bill = new TblStudyFeeController().FetchAll().Where(x => x.UserId == user.UserId && x.Active == true).Last();
                    DateTime now = DateTime.Now;
                    DateTime exp = DateTime.Parse(get_bill.ExpDate.ToString());
                    TimeSpan remain = exp.Subtract(now);
                    int day = remain.Days;
                    if (day > 0)
                        day++;      
    %>
    <li class="w3-padding w3-row">
        <div class="w3-col l2">
            <%if (!string.IsNullOrEmpty(user.NumberStudy))
              { %>
            <span><%=user.NumberStudy %></span>
            <%}
              else
              { %>
            <span>&nbsp;</span>
            <%} %>
        </div>
        <div class="w3-col l5">
            <span><%=user.FullName%></span>
        </div>
        <div class="w3-col l3">
            <span><%=get_class.ClassName%></span>
        </div>
        <%if (day > 14)
          {%>
        <div class="w3-col l2">
            <span class=" w3-text-teal"><i class="fa fa-thumbs-o-up"></i>&nbsp;<%=day%> ngày</span>
        </div>
        <%}
          else
          { %>
        <%if (day >= 7 && day <= 14)
          { %>
        <div class="w3-col l2">
            <span class=" w3-text-orange"><i class="fa fa-exclamation-triangle"></i>&nbsp;<%=day%> ngày</span>
        </div>
        <%}
          else
          { %>
        <div class="w3-col l2">
            <span class=" w3-text-red"><i class="fa fa-times-circle"></i>&nbsp;<%=day%> ngày</span>
        </div>
        <%}
          } %>
    </li>
    <%
                }
                else
                {
    %>
    <li class="w3-padding w3-row">
        <div class="w3-col l2">
            <%if (!string.IsNullOrEmpty(user.NumberStudy))
              { %>
            <span><%=user.NumberStudy %></span>
            <%}
              else
              { %>
            <span>&nbsp;</span>
            <%} %>
        </div>
        <div class="w3-col l5">
            <span><%=user.FullName%></span>
        </div>
        <div class="w3-col l3">
            <span><%=get_class.ClassName%></span>
        </div>
        <div class="w3-col l2">
            <span class=" w3-text-grey">Chưa đóng</span>
        </div>
    </li>
    <%
                }
            }
        }
        else
        {
            var get_class = (from p in new TblClassController().FetchAll().Where(x => x.Active == true && x.Id != 0) orderby p.Id descending select p);
            foreach (TblClass cls in get_class)
            { %>
    <%var get_user = new TblUserController().FetchAll().Where(x => x.ClassX == cls.Id);
      foreach (TblUser user in get_user)
      {
          var get_user_bill = new TblStudyFeeController().FetchAll().Where(x => x.UserId == user.UserId).ToList();
          if (get_user_bill.Count != 0)
          {
              var get_bill = new TblStudyFeeController().FetchAll().Where(x => x.UserId == user.UserId && x.Active == true).Last();
              DateTime now = DateTime.Now;
              DateTime exp = DateTime.Parse(get_bill.ExpDate.ToString());
              TimeSpan remain = exp.Subtract(now);
              int day = remain.Days;
              if (day > 0)
                  day++;      
    %>
    <li class="w3-padding w3-row">
        <div class="w3-col l2">
            <%if (!string.IsNullOrEmpty(user.NumberStudy))
              { %>
            <span><%=user.NumberStudy %></span>
            <%}
              else
              { %>
            <span>&nbsp;</span>
            <%} %>
        </div>
        <div class="w3-col l5">
            <span><%=user.FullName%></span>
        </div>
        <div class="w3-col l2">
            <span><%=cls.ClassName%></span>
        </div>
        <%if (day > 14)
          {%>
        <div class="w3-col l3">
            <span class=" w3-text-teal"><i class="fa fa-thumbs-o-up"></i>&nbsp;<%=day%> ngày</span>
        </div>
        <%}
          else
          { %>
        <%if (day >= 7 && day <= 14)
          { %>
        <div class="w3-col l3">
            <span class=" w3-text-orange"><i class="fa fa-exclamation-triangle"></i>&nbsp;<%=day%> ngày</span>
        </div>
        <%}
          else
          { %>
        <span class=" w3-text-red"><i class="fa fa-times-circle"></i>&nbsp;<%=day%> ngày</span>
        <%}
          } %>
    </li>
    <%
          }
          else
          {
    %>
    <li class="w3-padding w3-row">
        <div class="w3-col l2">
            <%if (!string.IsNullOrEmpty(user.NumberStudy))
              { %>
            <span><%=user.NumberStudy %></span>
            <%}
              else
              { %>
            <span>&nbsp;</span>
            <%} %>
        </div>
        <div class="w3-col l5">
            <span><%=user.FullName%></span>
        </div>
        <div class="w3-col l2">
            <span><%=cls.ClassName%></span>
        </div>
        <div class="w3-col l3">
            <span class=" w3-text-grey">Chưa đóng</span>
        </div>
    </li>
    <%
          }
      }
            } %>
    <%
        }
    %>
</body>
</html>
